#include <iostream>
#include "Watch.h"

using namespace std;

void IterativeFibonacci( int n );
int RecursiveFibonacci( int n );
void LoopRecursiveFibonacci( int n );

#pragma optimize("",off)


int main( void )
{
	Course::Watch w;

	int n = 5;
	for( int i = 0; i < 7; i++ )
	{
		
		cout << "Iterative(" << n << "):" << endl;
		w.restart();
		IterativeFibonacci(n);
		cout << "\nElapsed microseconds: " << w.elapsedUs().count();

		cout << endl;
		cout << "Recursive(" << n << "):" << endl;
		w.restart();
		LoopRecursiveFibonacci(n);
		cout << "\nElapsed microseconds: " << w.elapsedUs().count();
		cout << endl;

		if( n >= 20 )
			n++;
		else
			n = n+5;
	}
	cin.get();
	return 0;
}


void LoopRecursiveFibonacci( int n )
{

	for( int i = 0; i < n; i++ )
	{
		cout << RecursiveFibonacci(i) << " ";
	}

}


int RecursiveFibonacci( int n )
{
	int a1, a0;
	a1 = a0 = 1;

	if( n < 2 )
	{
		return 1;
	}
	else
	{
		a1 = RecursiveFibonacci( n - 1 );
		a0 = RecursiveFibonacci( n - 2 );
		return a1+a0;
	}

}


void IterativeFibonacci( int n )
{
	int a2, a1, a0;
	a1 = a0 = 1;
	a2 = 0;

	for( int i = 0; i < n; i++ )
	{
		if( i < 2 )
			cout << 1 << " ";
		else
		{
			a2 = a1 +  a0;
			cout << a2 << " ";
			a0 = a1;
			a1 = a2;
		}
	}
}